using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace XFNRelationsPlugIn
{
	/// <summary>
	/// Summary description for SmartXFNRelationsContentEditor.
	/// </summary>
	public class SmartXFNRelationsContentEditor : SmartContentEditor
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private XFNRelationsPlugIn.XFNRelationsControl xfnRelationsControl1;
		private ISmartContentEditorSite _contentEditorSite;
		private XFNRelationsSettings _settings;
		private XFNRelationsSettings _defaultSettings;
		public SmartXFNRelationsContentEditor(ISmartContentEditorSite contentEditorSite, XFNRelationsSettings defaultSettings)
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			_contentEditorSite = contentEditorSite;
			_defaultSettings = defaultSettings;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.xfnRelationsControl1 = new XFNRelationsPlugIn.XFNRelationsControl();
            this.SuspendLayout();
            // 
            // xfnRelationsControl1
            // 
            this.xfnRelationsControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.xfnRelationsControl1.Location = new System.Drawing.Point(3, 3);
            this.xfnRelationsControl1.Message = "<a  href=\"Hello World!\" target=\"_blank\"rel=\"\"></a>";
            this.xfnRelationsControl1.Name = "xfnRelationsControl1";
            this.xfnRelationsControl1.Size = new System.Drawing.Size(204, 442);
            this.xfnRelationsControl1.TabIndex = 0;
            this.xfnRelationsControl1.MessageChanged += new System.EventHandler(this.helloWorldControl1_MessageChanged);
            // 
            // SmartXFNRelationsContentEditor
            // 
            this.Controls.Add(this.xfnRelationsControl1);
            this.Name = "SmartXFNRelationsContentEditor";
            this.Size = new System.Drawing.Size(220, 361);
            this.ResumeLayout(false);

		}
		#endregion

		protected override void OnSelectedContentChanged()
		{
			base.OnSelectedContentChanged();
			_settings = new XFNRelationsSettings(SelectedContent.Properties);
			xfnRelationsControl1.Message = _settings.Message;
		}

		private void helloWorldControl1_MessageChanged(object sender, System.EventArgs e)
		{
			//update the smart content settings
			_settings.Message = xfnRelationsControl1.Message;
			_defaultSettings.Message = _settings.Message; //save the new message as the default

			//notify the editor that the smart content has changed, so it will regenerate the html.
			OnContentEdited();
		}
	}
}
